package com.zp.common.core.utils;

import cn.hutool.core.lang.UUID;

public class CommonUtils {
    /**
     * 获取出生日期  yyyy年MM月dd日
     *
     * @param IDCard
     * @return
     */
    public static String getBirthday (String IDCard) {
        String birthday = "";
        String year = "";
        String month = "";
        String day = "";
        if (org.apache.commons.lang3.StringUtils.isNotBlank(IDCard)) {
            //15位身份证号
            if (IDCard.length() == 15) {
                // 身份证上的年份(15位身份证为1980年前的)
                year = "19" + IDCard.substring(6, 8);
                //身份证上的月份
                month = IDCard.substring(8, 10);
                //身份证上的日期
                day = IDCard.substring(10, 12);
                //18位身份证号
            } else if (IDCard.length() == 18) {
                // 身份证上的年份
                year = IDCard.substring(6).substring(0, 4);
                // 身份证上的月份
                month = IDCard.substring(10).substring(0, 2);
                //身份证上的日期
                day = IDCard.substring(12).substring(0, 2);
            }
            birthday = year + "/" + month + "/" + day + "";
        }
        return birthday;
    }

    /**
     * 身份证中获取性别
     *
     * @param IDCard
     * @return
     */
    public static String getSex (String IDCard) {
        String sexName = "0";
        if (IDCard.length() == 15) {
            String sex = IDCard.substring(14, 15);
            if (Integer.parseInt(sex) % 2 == 0) {
                sexName = "2";
            } else {
                sexName = "1";
            }
        }
        if (IDCard.length() == 18) {
            String sex = IDCard.substring(16, 17);
            if (Integer.parseInt(sex) % 2 == 0) {
                sexName = "2";
            } else {
                sexName = "1";
            }
        }
        return sexName;
    }


    /**
     * 获取UUID
     *
     * @return
     */
    public static String getUUID () {
        /* return UUID.fastUUID().toString().replace("-","");*/
        return UUID.fastUUID().toString().replace("-" , "");
    }
}
